package com.radio.view;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Vector;

public class Util extends RadioProgram{

	BufferedReader br;
	BufferedWriter bw;
	
	protected void fileWrite(){
		try {    
			bw = new BufferedWriter(new FileWriter("./values/lastesFrequency.xml"));
		   
			bw.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
		    bw.append("<resources>\n");
		    for (int i = 0; i < 10; i++){
			    bw.append("\t<Frequency>\n");
			    bw.append("\t\t" + i + "\n");
			    bw.append("\t</Frequency>\n");
		    }
		    bw.append("</resources>\n");
		   
		    bw.close();    
		  } catch (IOException e) {
		   System.err.println(e);
		   System.exit(1);
		  }
	}
	
	protected Vector<String> fileVectorRead(){
		String s = null;
		int i;
		Vector<String> temp = new Vector<String> ();  
		try {    
			br = new BufferedReader(new FileReader("./values/lastesFrequency.xml"));

			while((s = br.readLine()) != null){
				if(s.contains("<Frequency>")){
					temp.add(br.readLine().trim());
				}
			}
			    
		  } catch (IOException e) {
			  System.err.println(e);
			  System.exit(1);
		  }
		  return temp;
	}
}